Repository navigation
[1405] 修复网关缺失 usage 时上下文占比闪回 0.0% - #35
Merged
Merged
Conversation
根因:qwen-token-plan-cn 等 OpenAI 兼容网关在长会话/多工具轮次时 经常整个流不回传 usage(实测 47 轮中 42 轮全零),全零 usage 经 message_end → message_usage 把页脚占比打回 0.0%。 e76cd05 只覆盖了事件缺 window 的回退,未覆盖 usage 本身全零。 四层防线: - openai-completions 流式请求声明 stream_options.include_usage - 流解析:全零 usage chunk 不覆盖已累积的真实用量 - agent loop:message_end 结算全零/缺失 usage 时回填最近已知 usage(仅内存与事件上报,落盘保留原始值,会话恢复逻辑不变) - TUI:message_usage 全零时沿用页脚当前占比描述 验证:tmux 实机 qwen4-max 只读 review 6 分钟 47 轮(42 轮全零 usage),页脚无 0.0% 闪回;新增 3 组回归测试。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
接 #23(e76cd05):
qwen-token-plan-cn / qwen4-max用久一些后页脚上下文占比仍会明显闪回 0.0%。根因
用真实会话日志 + 网关直接探测确认:OpenAI 兼容网关在长会话/多工具轮次时经常整个流都不回传 usage(实测一次 47 轮的 review 会话中 42 轮 assistant usage 全零,且都是正常
toolUse响应,非错误占位)。全零 usage 经
message_end → message_usage事件链把页脚占比打回 0.0%。#23 只修了「事件缺 window」的回退,未覆盖「usage 本身全零」这条路径。修复(四层防线)
ai/.../openai-completions/msg.scmstream_options: {include_usage: true}(标准协议字段)ai/.../openai-completions/stream-parse.scmagent/liii/pi/agent/loop.scmmessage_end结算时全零/缺失 usage 回填最近一条已知 usage;仅作用于内存结算与事件上报,落盘保留原始值,会话恢复「跳过全零 usage」逻辑不变app/.../app-events.scmmessage_usage全零时沿用页脚当前占比描述(UI 兜底)验证
gf pi --provider qwen-token-plan-cn --model qwen4-max只读 review 当前分支 6 分钟 / 47 轮,其中 42 轮网关返回全零 usage,页脚全程无 0.0% 闪回(修复前每次全零轮都会归零)stream_options均回 usage;长会话多工具轮次时缺失 → 确认是网关行为,客户端防线必要run-agent-loop-zero-usage-test.scm(回退仅内存生效、落盘保留全零、无已知值不误填)process-openai-chunk-test.scm全零 chunk 不清零用例openai-build-request-body-test.scminclude_usage 断言pi-app-context-usage-test.scm全零 usage 不归零用例gf fmt已过已知边界
网关持续不回 usage 时,占比沿用最后已知值(客户端无法凭空得知真实增长),
↑↓token 统计同理不再被全零污染。